package com.itelite.common.util;

import com.itelite.domain.dto.Term;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @author 沈洋 邮箱:1845973183@qq.com
 * @create 2021/8/9-1:46
 **/
public class DateUtils {
    public static List<Term> getTerms() throws ParseException {
        List<Term> terms = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        String pat = "yyyy-MM";
        SimpleDateFormat sdf = new SimpleDateFormat(pat);
        int now = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH)+1;
        if(month>=9) now++;
        for (int i = now-1; i >=2019; i--) {
            Term t = new Term();
            t.setSchoolYear(i+"-"+(i+1)+"学年");
            String strDate = i+"-09";
            t.setSuperior(sdf.parse(strDate));
            strDate = (i+1)+"-03";
            t.setMid(sdf.parse(strDate));
            strDate = (i+1)+"-09";
            t.setDown(sdf.parse(strDate));
            terms.add(t);
        }
        return terms;
    }
}
